import { useIntersectionObserver } from '@vueuse/core'
export default {
  lazyImg: {
    mounted (dom, obj) {
      useIntersectionObserver(
        dom,
        ([{ isIntersecting }], observerElement) => {
          if (isIntersecting) {
            dom.src = obj.value
          }
        },
        {
          thresholds: [0]
        }
      )
    },
    updated (dom, obj) {
      if (obj.oldValue !== obj.value) {
        useIntersectionObserver(
          dom,
          ([{ isIntersecting }], observerElement) => {
            if (isIntersecting) {
              dom.src = obj.value
            }
          },
          {
            thresholds: [0]
          }
        )
      }
    }
  }
}
